package com.company.app.daoImpl;

import java.util.List;

import org.springframework.dao.DataAccessException;

import com.company.app.dao.AbstractBaseDAO;
import com.company.app.dao.CustomerDAO;
import com.company.app.entities.Customer;
import com.google.code.ssm.api.InvalidateSingleCache;
import com.google.code.ssm.api.ParameterValueKeyProvider;
import com.google.code.ssm.api.ReadThroughMultiCache;
import com.google.code.ssm.api.ReadThroughMultiCacheOption;
import com.google.code.ssm.api.ReadThroughSingleCache;
import com.google.code.ssm.api.ReturnDataUpdateContent;
import com.google.code.ssm.api.UpdateSingleCache;

/**
 * The Class CustomerDAOImpl.
 */
public class CustomerDAOImpl extends AbstractBaseDAO<Customer> implements
		CustomerDAO {

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.company.app.dao.CustomerDAO#getCustomerByEmail(java.lang.String)
	 */
	@Override
	public Customer getCustomerByEmail(String email) throws DataAccessException {
		return (Customer) getSqlSession().selectOne(
				"com.company.app.dao.ClientMapper.getClientByEmail", email);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.company.app.dao.CustomerDAO#getCustomerBySpecificLogic()
	 */
	@Override
	public Customer getCustomerBySpecificLogic() throws DataAccessException {
		// getSqlMapClientTemplate().update("insertCompany", company);
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.company.app.dao.BaseInterfaceDAO#getEntityById(java.lang.Long)
	 */
	@Override
	@ReadThroughSingleCache(namespace = MEMCHACHED_NAMESPACE, expiration = 60)
	public Customer getEntityById(@ParameterValueKeyProvider Long id) {
		return (Customer) this.getSqlSession().selectOne(
				"com.company.app.dao.CustomerMapper.getCustomerById", id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.company.app.dao.BaseInterfaceDAO#getAllEntity()
	 */
	@Override
	public List<Customer> getAllEntity() {
		return this.getSqlSession().selectList(
				"com.company.app.dao.CustomerMapper.getAllCustomers");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.company.app.dao.BaseInterfaceDAO#searchEntityByFilter(java.lang.Object
	 * )
	 */
	@Override
	@ReadThroughMultiCache(namespace = MEMCHACHED_NAMESPACE, expiration = 180, option = @ReadThroughMultiCacheOption(generateKeysFromResult = true, skipNullsInResult=true ))
	public List<Customer> searchEntities(
			@ParameterValueKeyProvider List<Customer> filter) {
		return this.getSqlSession().selectList(
				"com.company.app.dao.CustomerMapper.getCustomerByFilter",
				filter.get(0));
	}
	
	/* (non-Javadoc)
	 * @see com.company.app.dao.AbstractBaseDAO#createEntity(java.lang.Object)
	 */
	@Override
	@UpdateSingleCache(namespace = MEMCHACHED_NAMESPACE)
	@ReturnDataUpdateContent
	public Customer createEntity(@ParameterValueKeyProvider Customer entity) {
		return super.createEntity(entity);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.company.app.dao.AbstractBaseDAO#updateEntity(java.lang.Object)
	 */
	@Override
	@UpdateSingleCache(namespace = MEMCHACHED_NAMESPACE, expiration = 180)
	@ReturnDataUpdateContent
	public Customer updateEntity(@ParameterValueKeyProvider Customer entity) {
		return super.updateEntity(entity);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.company.app.dao.AbstractBaseDAO#deleteEntity(java.lang.Object)
	 */
	@Override
	@InvalidateSingleCache(namespace = MEMCHACHED_NAMESPACE)
	public Customer deleteEntity(@ParameterValueKeyProvider Customer entity) {
		return super.deleteEntity(entity);
	}

}
